package com.hxx.day1.service.impl;


import com.hxx.day1.service.StudentService;

public class StudentServiceImpl implements StudentService {
    private int[] db = new int[3];
    @Override
    public void save(int i) {
        int index = find(0);
        if (index != -1){
            db[index] = i;
        }else {
            System.out.println("数据库已满");
        }
    }

    @Override
    public void delete(int i) {
        int index = find(i);
        if (index != -1){
            db[index] = 0;
        }else {
            System.out.println("数据库中没有该数据");
        }
    }

    @Override
    public void update(int i,int n) {
        int index = find(i);
        if (index != -1){
            db[index] = n;
        }else {
            System.out.println("数据库中没有该数据");
        }
    }

    @Override
    public int find(int i) {
        for (int index = 0; index < db.length; index++) {
            if (db[index] == i){
                return index;
            }
        }
        return -1;
    }

    @Override
    public void findAll() {
        for (int index = 0; index < db.length; index++) {
            System.out.println(db[index]!=0?db[index]:"");
        }
    }
}
